package com.itbz.servlet;

import com.google.gson.Gson;
import com.itbz.pojo.Room;
import com.itbz.service.Impl.RoomServiceImpl;
import com.itbz.service.RoomService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/www/RoomServlet")
public class RoomServlet extends HttpServlet {
    private RoomService roomService=new RoomServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        if ("findAll".equals(method)) {
            findAll(req,resp);
    }
}

    private void findAll(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //2.数据处理 返回结果
        List<Room> list = roomService.allSelect();
        //3.根据返回结果给用户做出响应
        String json = new Gson().toJson(list);
        resp.getWriter().print(json);
    }
}
